﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<base href="<%=basePath%>">
<!-- 下拉框 -->
<link rel="stylesheet" href="static/ace/css/chosen.css" />
<!-- jsp文件头和头部 -->
<%@ include file="../../system/index/top.jsp"%>
<!-- 日期框 -->
<link rel="stylesheet" href="static/ace/css/datepicker.css" />
</head>
<body class="no-skin">

	<!-- /section:basics/navbar.layout -->
	<div class="main-container" id="main-container">
		<!-- /section:basics/sidebar -->
		<div class="main-content">
			<div class="main-content-inner">
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12">
							<!-- 检索  -->
							<form action="areagoodscount/list" method="post"
								name="areagoodscountForm" id="areagoodscountForm">
								<input type="hidden" name="baseId" id="baseId" value="${pd.baseId }" /> 
								<input type="hidden" name="baseName" id="baseName" value="${pd.baseName }" />
								 <input type="hidden" name="baseAreaId" id="baseAreaId" value="${pd.baseAreaId }" />
								<input type="hidden" name="areaName" id="areaName" value="${pd.areaName }" /> 
								<input type="hidden" name="areaCode" id="areaCode" value="${pd.areaCode }" /> 
								<input type="hidden" name="baseCode" id="baseCode" value="${pd.baseCode }" />
								<table style="margin-top: 5px;">
									<tr>
										<td>
											<div class="nav-search">
												<span class="input-icon"> <input
													class="nav-search-input" autocomplete="off"
													id="nav-search-input" type="text" name="goodsName"
													value="${pd.goodsName }" placeholder="这里输入商品名称" /> <i
													class="ace-icon fa fa-search nav-search-icon"></i>
												</span>
											</div>
										</td>
										<c:if test="${QX.cha == 1 }">
											<td style="vertical-align: top; padding-left: 2px;"><a
												class="btn btn-light btn-xs" onclick="searchs();" title="检索"><i
													id="nav-search-icon"
													class="ace-icon fa fa-search bigger-110 nav-search-icon blue"></i></a></td>
										</c:if>
									</tr>
								</table>

								<!-- 检索  -->
								<table id="simple-table"
									class="table table-striped table-bordered table-hover"
									style="margin-top: 5px;">
									<thead>
										<tr>
											<th class="center" style="width: 35px;"><label
												class="pos-rel"><input type="checkbox" class="ace"
													id="zcheckbox" /><span class="lbl"></span></label></th>
											<th class="center">ID</th>
											<th class="center">批次编号</th>
											<th class="center">基地ID</th>
											<th class="center">基地名称</th>
											<th class="center">区域ID</th>
											<th class="center">区域名称</th>
											<th class="center">商品规格ID</th>
											<th class="center">商品名称</th>
											<th class="center">总数量</th>
											<th class="center">已订购数量</th>
											<th class="center"><i
												class="ace-icon fa fa-clock-o bigger-110 hidden-480"></i>种植日期</th>
											<th class="center">操作人ID</th>
											<th class="center">状态</th>
											<th class="center">操作</th>
										</tr>
									</thead>
									<tbody>

										<!-- 开始循环 -->
										<c:choose>
											<c:when test="${not empty areaGoodsList}">
												<c:if test="${QX.cha == 1 }">
													<c:forEach items="${areaGoodsList}" var="areaGood"
														varStatus="vs">
														<tr>
															<td class='center' style="width: 30px;"><label><input
																	type='checkbox' name='ids' value="${areaGood.id }"
																	class="lbl"> </span></label></td>
															<td class='center' style="width: 30px;">${areaGood.id}</td>
															<td class="center">${areaGood.batchNumber }</td>
															<td class="center">${areaGood.baseId }</td>
															<td class="center">${areaGood.baseName }</td>
															<td class="center">${areaGood.baseAreaId }</td>
															<td class="center">${areaGood.areaName }</td>
															<td class="center">${areaGood.goodsSpecId }</td>
															<td class="center">${areaGood.goodsName }</td>
															<td class="center">${areaGood.num }</td>
															<td class="center">${areaGood.takeNum }</td>
															<td class="center">${areaGood.birthday }</td>
															<td class="center">${areaGood.operatorId}</td>
															<td class="center" name="state">
																<c:if test="${areaGood.state=='00'}">未上架</c:if>
																<c:if test="${areaGood.state=='01'}">已上架</c:if>
															</td>
															<td class="center"  style="width: 120px;"><c:if test="${QX.cha == 1 }">
																	<a class="btn btn-xs btn-success" title="商品详情"
																		onclick="viewAreaGood('${areaGood.id}','${areaGood.state}');"> <i
																		class="ace-icon fa fa-eye" title="商品详情"></i>
																	</a>
																</c:if> 
																<c:if test="${QX.edit == 1 }">
																<c:if test="${areaGood.state=='00'}">
																	<a class="btn btn-xs btn-success" title="上架"
																		onclick="editGoodState('${areaGood.state}','${areaGood.id}','01','${areaGood.version}')"> 
																		<i class="ace-icon fa fa-unlock bigger-120" title="上架"></i>
																	</a>
																	<a class="btn btn-xs" title="下架" 
																	onclick="editGoodState('${areaGood.state}','${areaGood.id}','00','${areaGood.version}')" >
																		<i class="ace-icon fa fa-lock bigger-120" title="下架"></i>
																	</a>
																</c:if>
																<c:if test="${areaGood.state=='01'}">
																	<a class="btn btn-xs " title="上架"
																		onclick="editGoodState('${areaGood.state}','${areaGood.id}','01','${areaGood.version}')"> 
																		<i class="ace-icon fa fa-lock bigger-120" title="上架"></i>
																	</a>
																	<a class="btn btn-xs btn-success" title="下架" 
																	onclick="editGoodState('${areaGood.state}','${areaGood.id}','00','${areaGood.version}')" >
																		<i class="ace-icon fa fa-unlock bigger-120" title="下架"></i>
																	</a>
																</c:if>
																	<%-- <a class="btn btn-xs btn-success" title="编辑"
																		onclick="editAreaGood('${areaGood.id}','02');"> <i
																		class="ace-icon fa fa-pencil-square-o bigger-120"
																		title="编辑"></i>
																	</a> --%>
																</c:if></td>
														</tr>
													</c:forEach>
												</c:if>
												<c:if test="${QX.cha == 0 }">
													<tr>
														<td colspan="100" class="center">您无权查看</td>
													</tr>
												</c:if>
											</c:when>
											<c:otherwise>
												<tr class="main_info">
													<td colspan="100" class="center">没有相关数据</td>
												</tr>
											</c:otherwise>
										</c:choose>
									</tbody>
								</table>
								<div class="page-header position-relative">
									<table style="width: 100%;">
										<tr>
											<td style="vertical-align: top;"><c:if
													test="${QX.add == 1 }">
													<a class="btn btn-mini btn-success" onclick="add('01');">新增</a>
												</c:if></td>
											<td style="vertical-align: top;"><c:if
													test="${QX.del == 1 }">
													<a title="批量删除" class="btn btn-mini btn-danger"
														onclick="delAreaGoods();"> <i
														class='ace-icon fa fa-trash-o bigger-120'></i>
													</a>
												</c:if></td>
											<td style="vertical-align: top;">
												<div class="pagination"
													style="float: right; padding-top: 0px; margin-top: 0px;">${page.pageStr}</div>
											</td>
										</tr>
									</table>
								</div>
							</form>
						</div>
						<!-- /.col -->
					</div>
					<!-- /.row -->
				</div>
				<!-- /.page-content -->
			</div>
		</div>
		<!-- /.main-content -->
		<!-- 返回顶部 -->
		<a href="#" id="btn-scroll-up"
			class="btn-scroll-up btn btn-sm btn-inverse"> <i
			class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
		</a>
	</div>
	<!-- /.main-container -->
	<!-- basic scripts -->
	<!-- 页面底部js¨ -->
	<%@ include file="../../system/index/foot.jsp"%>
	<!-- 删除时确认窗口 -->
	<script src="static/ace/js/bootbox.js"></script>
	<!-- ace scripts -->
	<script src="static/ace/js/ace/ace.js"></script>
	<!-- 日期框 -->
	<script src="static/ace/js/date-time/bootstrap-datepicker.js"></script>
	<!-- 下拉框 -->
	<script src="static/ace/js/chosen.jquery.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</body>
<script type="text/javascript">
		$(top.hangge());
		$(function() {
			//复选框全选控制
			var active_class = 'active';
			$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
				var th_checked = this.checked;//checkbox inside "TH" table header
				$(this).closest('table').find('tbody > tr').each(function(){
					var row = this;
					if(th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
					else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
				});
			});
		});
		
		//检索
		function searchs(){
			top.jzts();
			$("#areagoodscountForm").submit();
		}
	
		 //新增
		function add(state){
			var baseName = $.trim($("#baseName").val());
			var baseId = $.trim($("#baseId").val());
			var baseAreaId = $.trim($("#baseAreaId").val());
			var areaName = $.trim($("#areaName").val());
			var areaCode = $.trim($("#areaCode").val());
			var baseCode = $.trim($("#baseCode").val());
			
			if(baseId==''||baseId==null){
				alert("请选择种植基地！");
				return false;
			}
			if(baseAreaId==''||baseAreaId==null){
				alert("请选择基地下的区域,新增商品！");
				return false;
			}
			top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="新增区域商品";
			 diag.URL = '<%=basePath%>areagoodscount/goAddG.do?state='+state+'&baseName='+baseName+'&baseId='+baseId+'&areaName='+areaName+'&baseAreaId='+baseAreaId+'&baseCode='+baseCode+'&areaCode='+areaCode;
			 diag.Width = 600;
			 diag.Height = 450;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 if('${page.currentPage}' == '0'){
						 top.jzts();
						 setTimeout("self.location=self.location",200);
					 }else{
						 nextPage('${page.currentPage}');
					 }
				}
				diag.close();
			 };
			 diag.show();
		} 
		// 查看区域商品详情
		function viewAreaGood(id,areaGoodState){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ='区域商品详情';
			 diag.URL = '<%=basePath%>areagoodscount/goViewG.do?id='+id+'&areaGoodState='+areaGoodState;
			 diag.Width = 800;
			 diag.Height = 550;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 //nextPage('${page.currentPage}');
					 if('${page.currentPage}' == '0'){
						 top.jzts();
						 setTimeout("self.location=self.location",200);
					 }else{
						 nextPage('${page.currentPage}');
					 }
				}
				diag.close();
			 };
			 diag.show();
		}

		//修改上下架状态
		function editGoodState(oldstate,id,state,version){
			if(oldstate==state){
				return false;
			}
			$.get("<%=basePath%>areagoodscount/updateState.do",{
				         id:id,
				        state:state,
				        version:version,
				        tm:new Date().getTime(),
				        },function(data){
				        //这里显示从服务器返回的数据
				       if("1"==data){
				    	   alert("操作成功");
				       }else if("2"==data){
				    	   alert("商品时间上架中，不能下架,修改失败");
				       }else{
				    	   alert("操作失败");
				       }
				        nextPage('${page.currentPage}');
				    });	
		}
		
		<%-- // 编辑
		function editAreaGood(id,state){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="修改区域商品";
			 diag.URL = '<%=basePath%>areagoodscount/goEditG.do?id='+id+'&state='+state;
			 diag.Width = 500;
			 diag.Height = 400;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 nextPage('${page.currentPage}');
				}
				diag.close();
			 };
			 diag.show();
		} --%>
			
		//批量删除
		function delAreaGoods(){
			var str='';
			for(var i=0;i < document.getElementsByName('ids').length;i++)
			{
				  if(document.getElementsByName('ids')[i].checked){
					  var $checkObj = $(document.getElementsByName('ids')[i]);
					  if($.trim($checkObj.parents('tr').find('td[name=state]').text())=='已上架'){
						  alert('存在已上架商品，不能删除');
						  return false;
					  }
				  	if(str==''){ 
				  		str += document.getElementsByName('ids')[i].value;
				  	}else{
				  		str += ',' + document.getElementsByName('ids')[i].value;
				  	}
				  }
			} 
		 	if(str==''){
				alert("请选择要删除的区域商品");
				return false;
			}else{ 
				bootbox.confirm("确定要删除吗?", function(result) {
					if(result) {
						$.ajax({
							type: "POST",
							url: '<%=basePath%>areagoodscount/deleteG.do?tm='+ new Date().getTime(),
						data : {
							ids : str,
							state:'00'
						},
						success : function(data) {
							if (data == "01") {
								alert("删除成功");
							}
							if (data == "00") {
								alert("删除失败");
							}
							if (data == "03") {
								alert("要删除的区域商品id不能为空");
							}
							if (data == "02") {
								alert("区域商品详情表存在商品，不能删除！");
							}
							nextPage('${page.currentPage}');
						}
					});
				}
			});
		}
	}
</script>
</html>
